package kr.co.skplanet.commute.controller.web;

import java.util.List;

import kr.co.skplanet.commute.dao.MemberDAO;
import kr.co.skplanet.commute.domain.Member;
import kr.co.skplanet.commute.domain.Post;
import kr.co.skplanet.commute.domain.Route;
import kr.co.skplanet.commute.service.PostService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class PostController {
	@Autowired
	PostService postService;

	@RequestMapping(value="/post/list", method = RequestMethod.GET)
	public String list(
			Model model
			){
		List<Post> list = postService.getPostList();
		model.addAttribute("list", list);

		return "/post/list";
	} // list 메소드 끝.

	@RequestMapping(value="/post/writeform", method = RequestMethod.GET)
	public String writeForm(
			Model model
			){
		return "/post/writeform";
	} // writeForm 메소드 끝.

	@RequestMapping(value="/post/write", method = RequestMethod.POST)
	public String write(
			@RequestParam(value="name", required=true)String name,
			@RequestParam(value="passwd", required=true)String passwd,
			@RequestParam(value="content", required=true)String content,
			Model model
			){
		Post post = new Post();
		post.setName(name);
		post.setPasswd(passwd);
		post.setContent(content);

		postService.savePost(post);

		return "redirect:/post/list";
	} // write 메소드 끝.
}
